const moment = require('moment')

const tencentcloud = require("tencentcloud-sdk-nodejs");

const SmsClient = tencentcloud.sms.v20190711.Client;
const models = tencentcloud.sms.v20190711.Models;

const Credential = tencentcloud.common.Credential;
const ClientProfile = tencentcloud.common.ClientProfile;
const HttpProfile = tencentcloud.common.HttpProfile;

let cred = new Credential("AKIDacOtBFLv7T5TghNTZR5Tbgw87sPph4nJ", "Zo4ACzvnV5ZDheNp1yg8wT1Pbu52kEUB");
let httpProfile = new HttpProfile();
httpProfile.endpoint = "sms.tencentcloudapi.com";
let clientProfile = new ClientProfile();
clientProfile.httpProfile = httpProfile;
let client = new SmsClient(cred, "ap-shanghai", clientProfile);

let req = new models.SendSmsRequest();

// let params = '{\"PhoneNumberSet\":[\"18500000000\"],\"TemplateID\":\"646584\",\"Sign\":\"BeAMuse\",\"TemplateParamSet\":[\"2020\",\"7\",\"1000\",\"30\",\"100\"],\"SmsSdkAppid\":\"1400372262\"}'
// req.from_json_string(params);


// client.SendSms(req, function(errMsg, response) {

//     if (errMsg) {
//         console.log(errMsg);
//         return;
//     }

//     console.log(response.to_json_string());
// });

module.exports.sendMemberPoint =  function sendMemberPoint(phone,point,expiredPoint,callback){
    let year = moment().subtract(1, 'days').format('YYYY');
    let month = moment().subtract(1, 'days').format('M');
    req.PhoneNumberSet=['+86'+phone],
    req.TemplateID = "646584",
    req.Sign = "BeAMuse",
    req.TemplateParamSet = [year,month,point,"30",expiredPoint],
    req.SmsSdkAppid = "1400372262"
    client.SendSms(req, function(errMsg, response) {
    
        if (errMsg) {
            console.log(errMsg);
            return;
        }
    
        console.log(response.to_json_string());
    });
}